/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pneuservis.backend.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

/**
 *
 * @author Admin
 */
@Entity
public class Customer implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String name;
    private String telephone;
    private String address;
    @JoinColumn(nullable=false)
    @LazyCollection(LazyCollectionOption.TRUE)
    @OneToMany
    private List<User> roles;
    @Column(nullable=false, unique=true, length=32)
    private String username;
    @Column(nullable=false, length=64)
    private String password;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public List<User> getRoles() {
        if (this.roles == null) {
                return null;
        }
        return Collections.unmodifiableList(this.roles);
    }

    public void setRoles(List<User> roles) {
        this.roles = null;

        if (roles != null) {
            this.roles = new ArrayList<User>();
            this.roles.addAll(roles);
        }
    }
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
        
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Customer)) {
            return false;
        }
        Customer other = (Customer) object;
        if (this.id != null && !this.id.equals(other.id)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Customer[ id=" + id + " ]";
    }
    
    public static Customer createInstance(String name, String adress, String telephone) {
        Customer result = new Customer();
        result.setName(name);
        result.setAddress(adress);
        result.setTelephone(telephone);
        return result;
    }
}
